package com.example.tvwanandroid.base

import io.reactivex.observers.DisposableObserver

/**
 * @作者: njb
 * @时间: 2020/12/3 17:29
 * @描述:
 */
abstract class BaseObserver <T> : DisposableObserver<T?>{
    private var view: BaseView?
    private var isShowDialog = false

    constructor(view: BaseView?) {
        this.view = view
    }

    constructor(view: BaseView?, isShowDialog: Boolean) {
        this.view = view
        this.isShowDialog = isShowDialog
    }

    override fun onStart() {
        if (isShowDialog) {
            view!!.showLoading()
        }
    }

    override fun onNext(o: T) {
        onSuccess(o)
    }

    override fun onError(e: Throwable) {
        if (isShowDialog) {
            view!!.hideLoading()
        }
        val be: BaseException
        onError("出现错误")
    }

    override fun onComplete() {
        if (isShowDialog) {
            view!!.hideLoading()
        }
    }

    abstract fun onSuccess(o: T)
    abstract fun onError(msg: String?)
}